package mop.controller;

import java.sql.Timestamp;
import java.util.List;

import mop.exception.IllegalIdException;
import mop.exception.IllegalReservationException;
import mop.exception.UnavailableResourceException;
import mop.model.World;
import mop.model.resource.Resource;
import mop.model.resource.ResourceInterface;
import mop.model.task.TaskInterface;

/**
 * MakeResourceReservationController
 * 
 * Use case controller for the making of new resource reservations. 
 * (use case 10)
 * 
 * @author	MOP Team 7
 */
public class MakeResourceReservationController extends UseCaseController
{

	/**
	 * Creates a MakeResourceReservationController.
	 * @see UseCaseController#UseCaseController(World)
	 */
	public MakeResourceReservationController(World world)
	{
		super(world);
	}
	
	/**
	 * Returns a list of all resources as interfaces.
	 * @see super#getAllResources()
	 */
	public List<ResourceInterface> getResourceList()
	{
		return super.getAllResources();
	}

        /**
	 * Returns a list of tasks belonging to the current user.
	 * @see super#getUserTasks()
	 */
	public List<TaskInterface> getUnfinishedTasks()
	{
		return super.getUserTasks();
	}
	
	/**
	 * Makes a reservation for the given resource and the given time period.
	 * 
	 * @param 	resource
	 * 			The description (as a String) of a resource.
	 * @param 	start
	 * 			Timestamp indicating the start time and date of the reservation.
	 * @param 	end
	 * 			Timestamp indicating the end time and date of the reservation.
	 * @throws 	UnavailableResourceException 
	 * 			Thrown when the resource is not available during the given time period.
	 * @throws 	IllegalReservationException
	 * 			Thrown when the reservation is invalid.
	 * @throws	IllegalIdException 
	 * 			Thrown when the given resource description is invalid.
	 */
	public void makeReservation(String resource, Timestamp start, Timestamp end) 
		throws IllegalReservationException, UnavailableResourceException, IllegalIdException
	{
		Resource r = getWorld().getResourceDataBase().find(resource);
		r.addReservation(start, end);
	}
	
	
	/***************************************************************************
	 * 								Visit
	 ***************************************************************************/
	
	/**
	 * Make a CallBack to the visitor
	 * @param v the visitor
	 */
	public void visit(ControllerVisitor v)
	{
		v.action(this);
	}

}